#include "netfdslist.h"

void initList(list_t *lt){
    lt->head=NULL;
    lt->tail=NULL;
    lt->list_length = 0;
    return;
}

void tailAdd(list_t* lt,int val){
    netfds_t* nt =(netfds_t*)malloc(sizeof(netfds_t));
    nt->nextnetfds = NULL;
    nt->val = val;
    if(lt->tail==NULL){
        lt->head = nt;
        lt->tail = nt;
        lt->list_length = 1;
        return;                                 
    }
    lt->tail->nextnetfds =nt;
    lt->tail = nt;
    lt->list_length+=1;
    return;
}

void headDel(list_t *lt){
    if(lt->head == NULL){
        printf("the list is null!\n");
        return;
    }
    if(lt->list_length == 1){
        netfds_t* temp = lt->head;
        lt->head = NULL;
        lt->tail = NULL;
        lt->list_length = 0;
        free(temp);
        return;
    }
    netfds_t* temp = lt->head;
    lt->head = lt->head->nextnetfds;
    lt->list_length-=1;
    free(temp);
    return;
}

void printfList(list_t lt){
    if(lt.head == NULL){
        printf("the list is null\n");
        return;
    }
    while(lt.head!=NULL){
        if(lt.head->nextnetfds == NULL){
            printf("%d\n",lt.head->val);
            return;
        }
        printf("%d->",lt.head->val);
        lt.head = lt.head->nextnetfds;
    }
    return;
}

